package ch11.d4;

import java.util.Random;

public class Cat extends Thread{
    int distance = 0;
    private Mouse 老鼠;//目标
    public void catchMouse(Mouse 老鼠) {
        this.老鼠 = 老鼠;
    }

    @Override
    public void run() {
        Random r=new Random();

        while (true) {
            distance+=r.nextInt(5);
            System.out.println("Cat running..."+distance+"米");
            if (distance >= 老鼠.distance) {
                老鼠.stop();
                System.out.println("Cat caught the mouse.");
                break;
            }
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }


        }


    }
}
